﻿using System;
using System.Xml.Serialization;

namespace QuickTuner
{
    /// <summary>
    /// Contains information for a single webradio station.
    /// </summary>
    [Serializable]
    [XmlRoot("Station")]
    public class Station : MarshalByRefObject
    {
        private string _title;
        private string _url;

        // properties _________________________________________________________

        /// <summary>
        /// Title of the station as should be visible to the user.
        /// </summary>
        public virtual string Title { get { return _title; } set { _title = value; } }

        /// <summary>
        /// URL of the listen-online page of the webradio station.
        /// </summary>
        /// <remarks>
        /// This should be the URL then when simply using Internet Explorer
        /// to browse to, immediatly plays the webradio stream.
        /// </remarks>
        public virtual string StationURL { get { return _url; } set { _url = value; } }

        // constructors _______________________________________________________

        public Station()
        {
            _title = string.Empty;
            _url = string.Empty;
        }

        // object overrides ___________________________________________________
        
        public override bool Equals(object obj)
        {
            var that = (Station)obj;

            var result = true;

            result &= (this.Title == that.Title);
            result &= (this.StationURL == that.StationURL);

            return result;
        }

        public override int GetHashCode()
        {
            // use a bitwise XOR of the title and url to differentiate
            int hash = (_title != null) ? _title.GetHashCode() : 0;
            hash ^= (_url != null) ? _url.GetHashCode() : 0;

            return hash;
        }

        public override string ToString()
        {
            return _title;
        }
    }
}
